//
//  AddLaederManagerVC.m
//  SelfDrivingTravelling-IOS
//
//  Created by Teplot_01 on 16/8/26.
//  Copyright © 2016年 Teplot_01. All rights reserved.
//

#import "AddLaederManagerVC.h"

@interface AddLaederManagerVC ()

@end

@implementation AddLaederManagerVC
{
    UITextField *_nameTF;
    UITextField *_IDCardTF;
    UITextField *_phoneTF;
    UITextField *_ageTF;
    UITextField *_passwordTF;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = White_Color;
    self.title = @"添加领队";
    [self initViewWithNewLeaderMan];
}
- (void)initViewWithNewLeaderMan{
    UILabel *_nameLb = [[UILabel alloc]initWithFrame:CGRectMake(20, 80, 100, 35)];
    _nameLb.text = @"真实姓名：";
    [self.view addSubview:_nameLb];
    _nameTF = [[UITextField alloc]initWithFrame:CGRectMake(120, 80, KScreenWidth - 140, 35)];
    _nameTF.placeholder = @"请输入真实姓名";
    _nameTF.layer.borderWidth = 1;
    _nameTF.layer.borderColor = Theme_Color.CGColor;
    _nameTF.layer.cornerRadius = 5;
    [self.view addSubview:_nameTF];
    
    UILabel *IDCardLb = [[UILabel alloc]initWithFrame:CGRectMake(20, 130, 100, 35)];
    IDCardLb.text = @"身份证号：";
    [self.view addSubview:IDCardLb];
    _IDCardTF = [[UITextField alloc]initWithFrame:CGRectMake(120, 130, KScreenWidth - 140, 35)];
    _IDCardTF.placeholder = @"请输入真实身份证号";
    _IDCardTF.layer.borderWidth = 1;
    _IDCardTF.layer.borderColor = Theme_Color.CGColor;
    _IDCardTF.layer.cornerRadius = 5;
    [self.view addSubview:_IDCardTF];
    
    UILabel *phoneLb = [[UILabel alloc]initWithFrame:CGRectMake(20, 180, 100, 35)];
    phoneLb.text = @"手机号：";
    [self.view addSubview:phoneLb];
    _phoneTF = [[UITextField alloc]initWithFrame:CGRectMake(120, 180, KScreenWidth - 140, 35)];
    _phoneTF.placeholder = @"请输入真实手机号";
    _phoneTF.layer.borderWidth = 1;
    _phoneTF.layer.borderColor = Theme_Color.CGColor;
    _phoneTF.layer.cornerRadius = 5;
    [self.view addSubview:_phoneTF];
    
    UILabel *ageLb = [[UILabel alloc]initWithFrame:CGRectMake(20, 230, 100, 35)];
    ageLb.text = @"年龄：";
    [self.view addSubview:ageLb];
    _ageTF = [[UITextField alloc]initWithFrame:CGRectMake(120, 230, KScreenWidth - 140, 35)];
    _ageTF.placeholder = @"请输入真实年龄";
    _ageTF.layer.borderWidth = 1;
    _ageTF.layer.borderColor = Theme_Color.CGColor;
    _ageTF.layer.cornerRadius = 5;
    [self.view addSubview:_ageTF];
    
    UILabel *passwordLb = [[UILabel alloc]initWithFrame:CGRectMake(20, 280, 100, 35)];
    passwordLb.text = @"密码：";
    [self.view addSubview:passwordLb];
    _passwordTF = [[UITextField alloc]initWithFrame:CGRectMake(120, 280, KScreenWidth - 140, 35)];
    _passwordTF.placeholder = @"请设置该领队的密码";
    _passwordTF.layer.borderWidth = 1;
    _passwordTF.layer.borderColor = Theme_Color.CGColor;
    _passwordTF.layer.cornerRadius = 5;
    [self.view addSubview:_passwordTF];
    
    UIButton *doneBtn = [[UIButton alloc]initWithFrame:CGRectMake(10, 350, KScreenWidth-20, 40)];
    doneBtn.tintColor = [UIColor whiteColor];
    [doneBtn setTitle:@"完成" forState:UIControlStateNormal];
    doneBtn.backgroundColor = Theme_Color;
    doneBtn.layer.cornerRadius = 5;
    [doneBtn addTarget:self action:@selector(doneBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:doneBtn];
    
}
- (void)doneBtnAction{
    //参数
    NSDictionary *parameters = @{
                                 @"phone":_phoneTF.text,
                                 @"realName": _nameTF.text,
                                 @"pass": _passwordTF.text,
                                 @"age":_ageTF.text,
                                 @"idCode": _IDCardTF.text,
                                 };
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.requestSerializer=[AFHTTPRequestSerializer serializer];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager POST:@"http://115.28.152.130/tour/v1/club/createLead.action" parameters:parameters success:^(NSURLSessionDataTask *operation, id responseObject) {
        [SVProgressHUD showWithStatus:@"创建中"];
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
        NSLog(@"%@>>>>",dic);
        NSString *error = dic[@"code"];
        if (![dic[@"code"] isEqualToString:@"0000"]) {
            [SVProgressHUD showErrorWithStatus:[NSString errorStringWithCode:error]];
        }else{
            //创建成功
            [SVProgressHUD showSuccessWithStatus:@"创建领队成功"];
            [[self navigationController] popViewControllerAnimated:YES];
        }
        
    } failure:^(NSURLSessionDataTask *operation, NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"创建失败"];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
